################################################################################
# Project: Konado
# File: konado_project_builder.gd
# Author: DSOE1024
# Created: 2025-08-03
# Last Modified: 2025-08-03
# Description:
#   Konado工程生成器
################################################################################

extends Node
class_name KonadoProjectBuilder


## 生成Godot工程
func gen_godot_project(project: KonadoProject, project_path: String, main_scene_path: String) -> void:
    var project_file_path = project_path + "/project.godot"
    if FileAccess.file_exists(project_file_path) == false:
        var project_file = FileAccess.open(project_file_path, FileAccess.WRITE)
        # 写入注释
        project_file.store_line("; This file was generated by the Konado project builder.")
        project_file.store_line("; Do not modify this file manually.")
        project_file.store_line("; Open the project in Konado Editor or Godot Engine to edit it.")
        project_file.store_line("")
        project_file.store_line("")
        project_file.store_line("config_version=5")
        project_file.store_line("")
            
        # 用configfile来写入project.godot文件
        var project_config = ConfigFile.new()
        project_config.set_value("application", "config/name", project.project_name)
        project_config.set_value("application", "config/version", project.project_version)
        project_config.set_value("application", "config/description", project.project_description)
        var features: PackedStringArray = ["4.4"]
        project_config.set_value("application", "config/features", features)

        # 获取指定路径场景文件或者UID
        project_config.set_value("application", "run/main_scene", main_scene_path)

        project_file.store_string(project_config.encode_to_text())
        project_file.close()
    else:
        print("project.godot已经存在，无法在此路径下生成工程")
